package dao;

import java.util.List;

import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.servlet.http.HttpSession;

import modelo.Imovel;
import modelo.Propaganda;
import modelo.Servico;

public class ServicoDao extends GenericJPADao<Servico>{
	
	public ServicoDao(){
		this.persistenceClass = Servico.class;
	}
	
	public List<Servico> getLista(){
		Query query = em.createQuery("SELECT s FROM Servico s");
		return (List<Servico>)query.getResultList();
	}

	public List<Servico> getListaTipo(){
		String gen =
				(String) ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false)).getAttribute("servico");
		Query query = em.createQuery("SELECT s FROM Servico s where genero=:genero");
		query.setParameter("genero", gen);
		return (List<Servico>)query.getResultList();
	}
	
	/*public boolean cadastrar(Servico servico){
		em.getTransaction().begin();
		
		try {
			em.persist(servico);
			em.getTransaction().commit();
			
			return true;
		} catch (Exception e) {		
			e.printStackTrace();
			return false;
		}
		
	}*/

	/*public boolean atualizar(Servico servico){
		em.getTransaction().begin();
		
		try {
			//funcao para fazer o update do servico
			em.merge(servico);
			em.getTransaction().commit();
			return true;
			
		} catch (Exception e) {
			return false;
		}
		
	}*/
	
	/*public Servico buscar(int id) {
		Servico servico = em.find(Servico.class, id);
		return servico;
	}*/
	
	/*public boolean excluir(int id){
		Servico servico = buscar(id);
		em.getTransaction().begin();
		em.remove(servico);
		em.getTransaction().commit();
		
		return true;
	}*/
	
}
